#!/bin/sh
# Use https://www.shellcheck.net/ to reduce mistakes if you make changes to this file.

setup_helm() {
    helm_version="${1}"
    echo "setup helm ${helm_version}"
    curl -sf https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | DESIRED_VERSION="${helm_version}" bash
}

await_jupyterhub() {
    kubectl rollout status --watch --timeout 300s deployment/proxy \
 && kubectl rollout status --watch --timeout 300s deployment/hub \
 && (
        if kubectl get deploy/autohttps > /dev/null 2>&1; then
            kubectl rollout status --watch --timeout 300s deployment/autohttps
        fi
    )
}

await_binderhub() {
    # accepts the release name as a parameter
    await_jupyterhub \
 && kubectl rollout status --watch --timeout 300s deployment/binder \
 && (
        if kubectl get "daemonset/${1}-dind" > /dev/null 2>&1; then
            kubectl rollout status --watch --timeout 300s "daemonset/${1}-dind"
        fi
    ) \
 && (
        if kubectl get "daemonset/${1}-image-cleaner" > /dev/null 2>&1; then
            kubectl rollout status --watch --timeout 300s "daemonset/${1}-image-cleaner"
        fi
    )
}
